//
//  TabBarViewController.m
//  BlocksKitLearn
//
//  Created by Elvis on 2017/8/17.
//  Copyright © 2017年 Elvis. All rights reserved.
//

#import "TabBarViewController.h"

#import "CoreViewController.h"
#import "DynamicDelegateViewController.h"
#import "MessageUIViewController.h"
#import "UIKitViewController.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置 UI
    [self setUpUI];
}


#pragma mark - Private

- (void)setUpUI{
    
    self.tabBar.accessibilityIdentifier = @"tabbar";
    
    //if 使tabBarController中管理的viewControllers都符合 UIRectEdgeNone
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        [self setEdgesForExtendedLayout: UIRectEdgeNone];
    }
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],
                                                        NSFontAttributeName:[UIFont fontWithName:@"Marion-Italic" size:24.0]}            forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor cyanColor],
                                                        NSForegroundColorAttributeName:[UIFont fontWithName:@"Marion-Italic" size:28.0]} forState:UIControlStateSelected];
    
    CoreViewController *coreVc = [[CoreViewController alloc] init];
    DynamicDelegateViewController *dynamicVc = [[DynamicDelegateViewController alloc] init];
    MessageUIViewController *messageVc = [[MessageUIViewController alloc] init];
    UIKitViewController *uiKitVc = [[UIKitViewController alloc] init];
    
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:coreVc];
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:dynamicVc];
    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:messageVc];
    UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:uiKitVc];
    
    [self setUpChidController:nav1 title:@"Core" image:nil SelectedImage:nil];
    [self setUpChidController:nav2 title:@"Dynamic" image:nil SelectedImage:nil];
    [self setUpChidController:nav3 title:@"MessageUI" image:nil SelectedImage:nil];
    [self setUpChidController:nav4 title:@"UIKit" image:nil SelectedImage:nil];
}

- (void)setUpChidController:(UIViewController *)viewController title:(NSString *)title image:(NSString *)image SelectedImage:(NSString *)selectImage{
    viewController.tabBarItem = [[UITabBarItem alloc] init];
    viewController.tabBarItem.title = title;
    if (image.length) {
        // 图片
        viewController.tabBarItem.image = [UIImage imageNamed:image];
        // 选中图片
        viewController.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    // 添加子控制器
    [self addChildViewController:viewController];
}

@end
